package edu.szu.huhanpeng.doodlingFight.view 
{
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.model.DisplayProxy;
	import edu.szu.huhanpeng.doodlingFight.view.components.ChessComponent;
	import flash.events.Event;
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class ChessMediator extends Mediator implements IMediator, INotifier 
	{
		public static const DIS_SELECT:String = "disSelect";
		
		/////////////////////////////////////////////////////////////////////
		//getter setter                                                    //
		/////////////////////////////////////////////////////////////////////
		protected function get chess():ChessComponent
		{
			return viewComponent as ChessComponent;
		}

		
		/////////////////////////////////////////////////////////////////////
		//构造函数                                                         //
		/////////////////////////////////////////////////////////////////////
		/**
		 * 
		 * @param	viewComponent
		 */
		public function ChessMediator( viewComponent:ChessComponent ) 
		{
			super( viewComponent.name, viewComponent );
			chess.addEventListener( GlobalConst.event.CHESS_CLICK, onClick );
		}
		
		
		/////////////////////////////////////////////////////////////////////
		//接口                                                             //
		/////////////////////////////////////////////////////////////////////
		
		override public function listNotificationInterests():Array 
		{
			return [ chess.name.concat(DIS_SELECT) ];
		}
		
		override public function handleNotification(note:INotification):void 
		{
			super.handleNotification( note );
			
			switch ( note.getName() ) 
			{
				//取消选中状态
				case chess.name.concat(DIS_SELECT):
					
						chess.selected = false;
					
				break;
				default:
			}
		}
		
		public function enableClick():void
		{
			chess.enableClick();
		}
		
		public function disableClick():void
		{
			chess.disableClick();
		}
		
		public function addEvent():void
		{
			chess.addEvent();
		}
		
		public function removeEvent():void
		{
			chess.removeEvent();
		}
		
		/////////////////////////////////////////////////////////////////////
		//内部                                                             //
		/////////////////////////////////////////////////////////////////////
		
		private function onClick(e:Event):void 
		{
			sendNotification( GlobalConst.noteName.CLICK_CHESS, chess.name );
		}
		
	}

}